package com.cmccgz.baselibrary.video;

import android.content.Intent;
import android.view.View;
import android.widget.ImageView;
import android.widget.TextView;

import com.cmccgz.baselibrary.R;
import com.cmccgz.baselibrary.base.BaseActivity;
import com.cmccgz.baselibrary.image.GlideUtils;

import cn.jzvd.JZVideoPlayer;
import cn.jzvd.JZVideoPlayerStandard;

public class VideoShowActivity extends BaseActivity implements View.OnClickListener {
    private TextView tv_back;
    private TextView tv_title;
    private JZVideoPlayerStandard video_show;
    public static final String KEY_VIDEO_URL="key_video_url";
    public static final String KEY_VIDEO_TITLE="key_video_title";
    public static final String KEY_COVER_URL="key_cover_url";
    private String video_url;
    private String cover_url;
    private String title;

    @Override
    protected int setLayoutId() {
        return R.layout.activity_video_show;
    }

    @Override
    protected void initView() {
        tv_back = ((TextView) findViewById(R.id.tv_back));
        tv_title = ((TextView) findViewById(R.id.tv_title));
        video_show = ((JZVideoPlayerStandard) findViewById(R.id.video_show));
        tv_back.setOnClickListener(this);

        initDatas();

        tv_title.setText(title==null?"":title);
        video_show.setUp(video_url, JZVideoPlayerStandard.SCREEN_LAYOUT_NORMAL,title);
        video_show.thumbImageView.setScaleType(ImageView.ScaleType.CENTER_CROP);
        GlideUtils.loadImage(mContext,cover_url,video_show.thumbImageView);
    }
    private void initDatas() {
        Intent intent = getIntent();
        video_url = intent.getStringExtra(KEY_VIDEO_URL);
        cover_url = intent.getStringExtra(KEY_COVER_URL);
        title = intent.getStringExtra(KEY_VIDEO_TITLE);
    }
    @Override
    protected void initFragment() {

    }

    @Override
    protected void beforePermission() {

    }

    @Override
    protected int setSystemBarColorId() {
        return R.color.black;
    }

    @Override
    public void onClick(View v) {
        if (v.getId()== R.id.tv_back) {
            onBackPressed();
        }
    }

    @Override
    public void onBackPressed() {
        if (JZVideoPlayer.backPress()) {
            return;
        }
        super.onBackPressed();
    }
    @Override
    protected void onPause() {
        super.onPause();
        JZVideoPlayer.releaseAllVideos();
    }
}
